from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from rest_framework.permissions import IsAdminUser
from django.contrib.auth.models import Permission,ContentType

from meiduo_admin.utils import PageNum
from meiduo_admin.serializers.permissions import PermissionSerializer, ContentTypeSerializer


class PermissionView(ModelViewSet):
    queryset = Permission.objects.all()
    pagination_class = PageNum
    serializer_class = PermissionSerializer
    permission_classes = [IsAdminUser]

    def content_type(self, request):
        """
         获取权限类型
        :param request:
        :return:
        """
        data = ContentType.objects.all()
        # 2、序列化返回权限类型  self.get_serializer() 获取serializer_class属性所指定的序列器对象
        ser = ContentTypeSerializer(data,many=True)
        return Response(ser.data)